using System;

namespace Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.NamingConventions
{
    /// <summary>
    /// Used by the templates to determine the DbTypeHelper strategy based
    /// on the provider as specified in the connection string.
    /// </summary>
    /// <remarks>
    /// This is really a factory method implementation and encapsulates the
    /// creation of naming strategies in a good enough manner.
    /// </remarks>
    public sealed class NamingStrategyFactory
    {
        private static SqlServerNamingStrategy _sqlServerNamingStrategy = null;
        private static OracleNamingStrategy _oracleNamingStrategy = null;

        /// <summary>
        /// Used by the templates to determine the DbTypeHelper strategy based
        /// on the provider as specified in the connection string.
        /// </summary>
        /// <param name="databaseProvider">The database provider name.</param>
        /// <returns>A strategy that implements the <see cref="IDbTypesHelperStrategy"/>.
        /// </returns>
        public static NamingStrategy Create(String databaseProvider)
        {
            if (String.Equals(databaseProvider, DatabaseProvider.SqlServer))
            {
                if (_sqlServerNamingStrategy == null)
                    _sqlServerNamingStrategy = new SqlServerNamingStrategy();
                return _sqlServerNamingStrategy;
            }

            if (String.Equals(databaseProvider, DatabaseProvider.MsOra) || 
                String.Equals(databaseProvider, DatabaseProvider.ODP))
            {
                if (_oracleNamingStrategy == null)
                    _oracleNamingStrategy = new OracleNamingStrategy();
                return _oracleNamingStrategy;
            }

            throw new Exception(
                String.Format("Database provider {0} not supported. Supported providers include:\n{1}\n{2}\n{3}"
                , databaseProvider, DatabaseProvider.SqlServer, DatabaseProvider.MsOra, DatabaseProvider.ODP));
        }
    }
}
